//package com.dhb.base.jobhandler;
//
//
//import com.alibaba.fastjson.JSONObject;
//import com.dhb.base.entity.ElectricEntity;
//import com.dhb.base.dao.OrderDao;
//import com.dhb.base.dao.OrderDetailCouponDao;
//import com.dhb.base.entity.OrderInfoEntity;
//import com.dhb.base.service.impl.HttpCouponServiceImpl;
//import com.xxl.job.core.biz.model.ReturnT;
//import com.xxl.job.core.handler.IJobHandler;
//import com.xxl.job.core.handler.annotation.JobHander;
//import com.xxl.job.core.log.XxlJobLogger;
//import org.springframework.stereotype.Service;
//
//import javax.annotation.Resource;
//import java.util.Calendar;
//import java.util.Date;
//import java.util.List;
//
///**
// * 设置订单过期，临时方案
// *
// * 开发步骤：
// * 1、继承 “IJobHandler” ；
// * 2、装配到Spring，例如加 “@Service” 注解；
// * 3、加 “@JobHander” 注解，注解value值为新增任务生成的JobKey的值;多个JobKey用逗号分割;
// * 4、执行日志：需要通过 "XxlJobLogger.log" 打印执行日志；
// *
// * @author xuxueli 2015-12-19 19:43:36
// */
//@JobHander(value="orderJobHandler")
//@Service
//public class DemoJobHandler extends IJobHandler {
//
//    @Resource
//    OrderDao orderDao;
//
//    @Resource
//    OrderDetailCouponDao orderDetailCouponDao;
//
//    @Resource
//    HttpCouponServiceImpl httpCouponServiceImpl;
//
//
//    private static Date startDate=null;
//
//    @Override
//    public ReturnT<String> execute(String... params) throws Exception {
//        XxlJobLogger.log("XXL-JOB, 执行订单过期定时器.");
//
//        String minute =params[0];
//        Calendar nowTime = Calendar.getInstance();
//        nowTime.add(Calendar.MINUTE,-Integer.valueOf(minute));
//        Date endDate=nowTime.getTime();
//
//        //第一次执行检查更新XX分钟之前所有订单(并且返还优惠券)
//        if(startDate==null){
//
//            List<OrderInfoEntity> orderInfoEntityList=orderDao.findOrderInfoEntityByCreateDate(endDate);
//            for(OrderInfoEntity orderInfoEntity:orderInfoEntityList){
//                List<ElectricEntity> orderDetailCouponEntitys= orderDetailCouponDao.findOrderCouponByOrderNo(orderInfoEntity.getOrderNo());
//                for(ElectricEntity orderDetailCouponDO:orderDetailCouponEntitys){
//                    JSONObject jsonObject=new JSONObject();
//                    jsonObject.put("serialCode",orderDetailCouponDO.getCouponId());
//                    httpCouponServiceImpl.getHttpCouponService().returnCoupon(jsonObject);
//                }
//
//            }
//
//
//            orderDao.updateOrderState(endDate);
//
//            startDate=endDate;
//        }else{
//
//            List<OrderInfoEntity> orderInfoEntityList=orderDao.findOrderInfoEntityByCreateDate(endDate,startDate);
//            for(OrderInfoEntity orderInfoEntity:orderInfoEntityList){
//                List<ElectricEntity> orderDetailCouponEntitys= orderDetailCouponDao.findOrderCouponByOrderNo(orderInfoEntity.getOrderNo());
//                for(ElectricEntity orderDetailCouponDO:orderDetailCouponEntitys){
//                    JSONObject jsonObject=new JSONObject();
//                    jsonObject.put("serialCode",orderDetailCouponDO.getCouponId());
//                    httpCouponServiceImpl.getHttpCouponService().returnCoupon(jsonObject);
//                }
//
//            }
//
//            orderDao.updateOrderState(endDate,startDate);
//        }
//
//
//        XxlJobLogger.log("XXL-JOB, 执行订单过期定时器完成.");
//
//
//        return ReturnT.SUCCESS;
//    }
//
//}
